package area

import (
	"Project/global"
	"Project/model/common/request"
	"Project/model/common/response"
	"Project/utils"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"log"
)

type RecordApi struct {}

// RecordInfo 获取记录
func (r *RecordApi) RecordInfo(c *gin.Context){
	var page request.PageRes
	if err := c.ShouldBindJSON(&page);err != nil {
		log.Println("绑定参数失败",err)
		global.GVA_LOG.Error("绑定参数失败",zap.Error(err))
		response.FailWithMessage("参数绑定失败",c)
		return
	}
	userID := utils.GetUserID(c)
	data,err := recordService.RecordInfo(userID,page)
	if err != nil{
		log.Println("获取记录列表失败")
		global.GVA_LOG.Error("获取记录列表失败",zap.Error(err))
		response.FailWithMessage("获取记录列表失败",c)
		return
	}
	response.OkWithDetailed(data,"获取成功",c)
}

// RecordPageInfo 分页查询
func (r *RecordApi) RecordPageInfo(c *gin.Context){
	var page request.PageQeryRes
	if err := c.ShouldBindJSON(&page);err != nil {
		log.Println("绑定参数失败",err)
		global.GVA_LOG.Error("绑定参数失败",zap.Error(err))
		response.FailWithMessage("参数绑定失败",c)
		return
	}
	userID := utils.GetUserID(c)
	data,err := recordService.RecordPageInfo(userID,page)
	if err != nil{
		log.Println("获取记录列表失败")
		global.GVA_LOG.Error("获取记录列表失败",zap.Error(err))
		response.FailWithMessage("获取记录列表失败",c)
		return
	}
	response.OkWithDetailed(data,"获取成功",c)
}